package cn.itcast.web.task;

import cn.itcast.domain.cargo.Contract;
import cn.itcast.domain.cargo.ContractExample;
import cn.itcast.domain.system.User;
import cn.itcast.service.cargo.ContractService;
import cn.itcast.service.system.UserService;
import cn.itcast.util.MailUtil;
import cn.itcast.web.controller.BaseController;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 定时执行的任务类
 */
public class MyTask extends BaseController {

    @Autowired
    private UserService userService;
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 定时执行的任务方法
     */
    // 业务处理
    public void execute() throws Exception {

        //查询交货期限前三天的用户
        List<User> userList = userService.findByMessageTime();
        //遍历
        for (User user : userList) {
            if (user.getEmail() != null && !"".equals(user.getEmail())){
                //发给谁
                String to = user.getEmail();
                //邮件标题
                String subject = "交货期限提醒";
                //邮件内容
                String content = "距离交货期限仅剩三天，麻烦您尽快处理！谢谢！";

                Map<String,String> map = new HashMap<>();
                map.put("to",to);
                map.put("subject",subject);
                map.put("content",content);
                rabbitTemplate.convertAndSend("msg.email",map);

            }
        }
    }
}
